<template>
  <!-- 修改病例病案页面 -->
  <div id="app">
    <!-- 设置顶部导航栏 -->
    <mt-header title="修 改 病 例 病 案">
      <mt-button icon="back" @click="goBack" slot="left">返回</mt-button>
      <mt-button slot="right" @click="goHome">
        <img
          src="../../assets/images/home.png"
          height="20"
          width="20"
          slot="icon"
          style="margin-top: 5px"
        />
      </mt-button>
    </mt-header>

    <van-cell-group>
      <van-field label="病例编号" v-model="patient.id" disabled />
      <van-field label="病例姓名" v-model="patient.username" disabled />
      <van-field label="病例身份证" v-model="patient.carid" disabled />
      <van-field label="入院时间" v-model="patient.createTime" disabled />
      <van-field
        label="病例病案"
        v-model="patient.description"
        type="textarea"
        rows="10"
        autosize
        border
        placeholder="请输入病案内容"
      />
    </van-cell-group>
    <!-- 上传附件 -->
    <!-- <div class="upload">
      <van-button round size="small" disabled type="warning"
        >上传附件</van-button
      >
      <van-uploader :after-read="afterRead" :max-count="1" v-model="fileList" />
    </div> -->

    <div class="btn">
      <van-button
        type="primary"
        round
        block
        @click="btnClick(patient.pid, patient.record)"
        >确认修改</van-button
      >
    </div>
  </div>
</template>

<script>
import { Dialog } from "vant";
import { Toast } from "vant";
import { Notify } from "vant";
export default {
  name: "Modifycase",

  data() {
    return {
      patientID: "", //页面一进来就回去url上面的pid
      //病人信息
      patient: {},
      //附件数组
      // fileList: [],
      //urlFile: null, //上传的文件
    };
  },

  created() {
    this.patientID = this.$route.query.id;
    Notify({
      type: "success",
      message: "当前修改的是编号为" + this.patientID + "号病人的病例",
      duration: 1500,
    });
    this.getMsg(this.patientID);
  },

  mounted() {},

  methods: {
    //获取病案信息
    getMsg(id) {
      this.$http.get("report/" + id, {}).then((res) => {
        console.log(res);
        this.patient = res.data.data;
      });
    },
    btnClick() {
      Dialog.confirm({
        title: "提醒",
        message: "是否确认修改病案信息",
        confirmButtonColor: "#07c160",
        cancelButtonColor: "#ff976a",
      })
        .then(() => {
          console.log(this.patient);
          //调用修改信息接口
          this.$http.post("report", this.patient).then((res) => {
            console.log(res);
            Toast({
              message: "修改成功",
              duration: 1500,
            });
            setTimeout(() => {
              this.$router.push({
                path:'./medicalCase'
              })
            }, 1500);
          });
        })
        .catch(() => {
          console.log("cancel");
        });
    },
    goBack() {
      this.$router.push({
        path: "./medicalCase",
      });
    },
    goHome() {
      this.$router.push({
        path: "./index",
      });
    },
    //文件读取完成后的回调函数
    /* afterRead(file) {
      this.urlFile  = file.file
      console.log(this.urlFile);

      this.$http.post("upload", { file: file.file }).then((res) => {
        console.log(res);
      });
      Toast("请预览");
    }, */
  },
};
</script>

<style lang="less" scoped>
#app /deep/ .mint-header-title {
  overflow: initial;
}
#app {
  position: absolute;
  height: 100%;
  width: 100%;
  background-color: #fff;
}
.btn {
  margin-top: 15px;
}
.upload {
  display: flex;
  align-items: center;
  margin-top: 10px;
  padding: 10px 0;
  .van-uploader {
    margin-left: 20px;
  }
}
</style>